{% from "pr-table.html" import pr_table with context %}
{% extends "layout.html" %}
{% block title %}CI{% endblock %}
{% block head %}
    <script src="{{ base_path }}/common_static/search_bar.js"></script>
    <script src="{{ base_path }}/common_static/focus_on_keyup.js"></script>
{% endblock %}
{% block content %}
    <h1>CI</h1>
    {% for wb in watched_branches %}
    <h2 class="stacked-header">{{ wb.branch }}</h2>
    <div class="attributes">
      <div>SHA:
	{% if wb.sha is not none %}
	{{ wb.sha }}
	{% else %}
	unknown
	{% endif %}
      </div>
      <div>Deploy State:
	{% if wb.deploy_state is not none %}
	{{ wb.deploy_state }}
	{% endif %}
      </div>
      <div>Deploy Batch:
	{% if wb.deploy_batch_id is not none %}
	<a rel="noopener" href="{{ base_path }}/batches/{{ wb.deploy_batch_id }}">{{ wb.deploy_batch_id }}</a>
	{% endif %}
      </div>
      <div>Merge Candidate:
    {% if wb.merge_candidate is not none %}
    {{ wb.merge_candidate }}
    {% endif %}
      </div>
    </div>

    <div>
      {% if not frozen_merge_deploy %}
      <form action="{{ base_path }}/freeze_merge_deploy" method="POST">
        <input type="hidden" name="_csrf" value="{{ csrf_token }}">
        <button class="dangerous">
          Freeze Merges & Deploys
        </button>
      </form>
      {% else %}
      <form action="{{ base_path }}/unfreeze_merge_deploy" method="POST">
        <input type="hidden" name="_csrf" value="{{ csrf_token }}">
        <button class="dangerous">
          Unfreeze Merges & Deploys
        </button>
      </form>
      {% endif %}
    </div>

    <h2>PRs</h2>
    {% if wb.prs is not none %}
    {% if wb.prs|length > 0 %}
    {{ pr_table(wb, "prs", "prsSearchBar") }}
    {% else %}
    No PRs.
    {% endif %}
    {% else %}
    Unknown.
    {% endif %}
    {% endfor %}

    <h2>Authorize SHA</h2>
    <form action="{{ base_path }}/authorize_source_sha" method="post">
      <label for="sha">SHA:</label>
      <input type="hidden" name="_csrf" value="{{ csrf_token }}"/>
      <input type="text" name="sha" id="sha">
      <button type="submit">Authorize</button>
    </form>
    <script type="text/javascript">
      focusOnSlash("prsSearchBar");
    </script>
{% endblock %}
